package com.penjin.android.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.penjin.android.R;
import com.penjin.android.activity.secretary.Data;
import com.penjin.android.domain.KaoqinLateDayData;
import com.penjin.android.domain.KaoqinPersonData;
import com.penjin.android.utils.BitmapUtils;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by fengjw on 2016/3/21.
 */
public class KaoqinLateAdapter extends BaseAdapter {

    private LayoutInflater mInflater;
    private Context mContext;

    List<KaoqinLateDayData> kaoqinLateDayDataList = new ArrayList<>();

    public KaoqinLateAdapter(Context context){
        mContext = context;
        mInflater = LayoutInflater.from(context);

    }

    public void setData(List<KaoqinLateDayData> kaoqinLateDayDatatList){
        this.kaoqinLateDayDataList = kaoqinLateDayDatatList;
    }

    @Override
    public int getCount() {
        return kaoqinLateDayDataList.size();
    }

    @Override
    public Object getItem(int i) {
        return kaoqinLateDayDataList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {

        KaoqinLateHolder holder;



        if(convertView == null){
            convertView=mInflater.inflate(R.layout.listview_kaoqin_late,null);
            KaoqinLateDayData data = kaoqinLateDayDataList.get(i);
            holder=new KaoqinLateHolder();
            holder.image=(ImageView)convertView.findViewById(R.id.image);
            holder.name=(TextView)convertView.findViewById(R.id.name);
            holder.department=(TextView)convertView.findViewById(R.id.department);
            holder.latenumber=(TextView)convertView.findViewById(R.id.number);


            holder.lateminute=(TextView)convertView.findViewById(R.id.minutes);


            holder.name.setText(data.getName());
            holder.department.setText(data.getDepartment());
            holder.lateminute.setText(data.getLateMintues()+"分钟");
            holder.latenumber.setText(data.getScore()+"次");
            //设置头像
            String url=data.getHeadUrl();
            if (url.equals("null")){
                Log.d("fengjw","url");
                holder.image.setImageResource(R.drawable.ease_default_avatar);
            }else {
                BitmapUtils.loadUrlImage(url, holder.image, mContext, true);
            }
            Log.v("fengjw",data.getName());

            convertView.setTag(holder);
        }else{
            holder=(KaoqinLateHolder)convertView.getTag();
        }


        return convertView;
    }

    class KaoqinLateHolder {

        public ImageView image;
        public TextView name;
        public TextView department;
        public TextView latenumber;
        public TextView lateminute;

    }

}
